/*
 * $Id: ServiceUtilities.java 42 2013-04-17 15:33:59Z gabakyan $
 * $Author: gabakyan $
 * $Revision: 42 $
 * $Date: 2013-04-17 15:33:59 +0000 (Wed, 17 Apr 2013) $
 *
 * Copyright (c) 2013 Supply Chain Intelligence (SCI), Inc.
 * http://www.scintelligence.com/, Email: info@scintelligence.com
 * All rights reserved.
 *
 * This file is part of Logistics Map.
 *
 * Logistics Map is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 3 of the License.
 *
 * Logistics Map is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Logistics Map.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.sci.logisticsmap.service.support;

import com.sci.logisticsmap.data.model.RuntimeConfigurationModel;
import com.sci.logisticsmap.data.model.UserModel;
import com.sci.logisticsmap.service.model.LocationImportTemplateDTModel;
import com.sci.logisticsmap.service.model.SessionUserDTModel;
import com.sci.logisticsmap.support.converter.ConversionUtilities;

/**
 * The utility class which provides helper methods for services.
 *
 * @author gabakyan@gmail.com (Last modified by $Author: gabakyan $)
 * @version $Revision: 42 $
 */
public final class ServiceUtilities {
    /**
     * The private constructor.
     */
    private ServiceUtilities() {
    }

    /**
     * Updates the session user.
     *
     * @param sessionUser The target session user model.
     * @param user The source user model.
     */
    public static void updateSessionUser(SessionUserDTModel sessionUser, UserModel user) {
        sessionUser.setUsername(user.getUsername());
        sessionUser.setPassword(user.getPassword());
        sessionUser.setFirstName(user.getFirstName());
        sessionUser.setLastName(user.getLastName());
        sessionUser.setEmail(user.getEmail());
        sessionUser.setAddress(user.getAddress());
        sessionUser.setCity(user.getCity());
        sessionUser.setState(user.getState());
        sessionUser.setZipCode(user.getZipCode());
        sessionUser.setCountry(user.getCountry());
        sessionUser.setTimeZone(user.getTimeZone());
        sessionUser.setLanguage(user.getLanguage());
        sessionUser.setType(user.getType());
        sessionUser.setStatus(user.getStatus());
        sessionUser.setCompany(user.getCompany());
        sessionUser.setPurpose(user.getPurpose());
        sessionUser.setRoles(user.getRoles());
    }

    /**
     * Updates the runtime configuration instance.
     *
     * @param runtimeConfiguration The source runtime configuration model.
     * @param conversionUtilities The conversion utilities.
     */
    public static void updateRuntimeConfigurationInstance(RuntimeConfigurationModel runtimeConfiguration, ConversionUtilities conversionUtilities) {
        RuntimeConfigurationInstance runtimeConfigurationInstance = RuntimeConfigurationInstance.INSTANCE;
        runtimeConfigurationInstance.setLockedDown(runtimeConfiguration.isLockedDown());
        runtimeConfigurationInstance.setApprovalOnlyMode(runtimeConfiguration.isApprovalOnlyMode());
        runtimeConfigurationInstance.setInvitationMode(runtimeConfiguration.isInvitationMode());
        if (runtimeConfiguration.getPrimaryLocationImportTemplate() != null) {
            runtimeConfigurationInstance.setPrimaryLocationImportTemplate(conversionUtilities.convert(runtimeConfiguration.getPrimaryLocationImportTemplate(), LocationImportTemplateDTModel.class));
        }
        if (runtimeConfiguration.getAllowedCountryCodes() != null) {
            runtimeConfigurationInstance.setAllowedCountryCodes(runtimeConfiguration.getAllowedCountryCodes());
        }
    }
}
